home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT10 / PMOUSE2.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  11.7 KB  |  229 lines

  1. ;***********************************************************************
  2. ;  Program PMouse2 ( Chapter 10 )
  3. ;
  4. ;  The demo program for mouse (the menu selection, Text Mode)
  5. ;
  6. ;  Author:  A.I.Sopin, Voronezh University. 1993
  7. ;
  8. ;  The interrupt 33h (mouse service) is used
  9. ;
  10. ;  Mouse driver must be installed
  11. ;
  12. ;***********************************************************************
  13. NAME    PMOUSE2
  14.         .DOSSEG
  15.         .MODEL  SMALL
  16.         .STACK  100h
  17. ;----------------------------------------------------------
  18.         .DATA
  19. BELL    EQU     07      ;  sound signal
  20. LF      EQU     10      ;  Line Feed
  21. CR      EQU     13      ;  Carriage Return
  22. TEXT0   DB      " The MOUSE demo program  (INT 33h). "
  23.         DB      "  Press any key to continue...", BELL, CR, LF, "$"
  24. TEXT1   DB      " The mouse driver is not installed !!!."
  25.         DB      "  Press any key...", BELL, CR, LF, "$"
  26. TEXT2   DB      " An active mouse driver found."
  27.         DB      "  Press any key...", BELL, CR, LF, "$"
  28. TEXT3   DB      'The menu command selection using the mouse (text mode).'
  29. Ltxt3   EQU     $-TEXT3
  30. TEXT8   DB      "Select Command and press Left Button:"
  31. Ltxt8   EQU     $-TEXT8
  32.  
  33. TEXT10  DB      "1 - Command one  "
  34. Ltxt10  EQU     $-TEXT10
  35. TEXT11  DB      "2 - Command two  "
  36. Ltxt11  EQU     $-TEXT11
  37. TEXT12  DB      "3 - Command three"
  38. Ltxt12  EQU     $-TEXT12
  39. TEXT13  DB      "4 - Command four "
  40. Ltxt13  EQU     $-TEXT13
  41. TEXT14  DB      "5 - Command five "
  42. Ltxt14  EQU     $-TEXT14
  43. TEXT15  DB      "6 - Exit         "
  44. Ltxt15  EQU     $-TEXT15
  45.  
  46. TXT3L   DB      "Left button pressed.  Command  "
  47. NumSel           DB      20h
  48.         DB       "   selected."
  49.         DB      BELL, "$"
  50.  
  51. VMODE   DB      0                                         ;  video mode saved
  52. ATTR    DB      0                       ;
  53. ROW0    DB      0
  54. COL0    DB      0
  55. CX0     DW      0
  56. DX0     DW      0
  57. ;----------------------------------------------------------
  58.         .CODE
  59. OutMsg           macro           Txt              ;=======   output text message
  60.         lea     dx,Txt                                             ;  adders of message
  61.         mov     ah,09h                  ;  function 09h - output text string
  62.         int     21h                     ;  DOS  service call
  63.         endm
  64.  
  65. WaitKey                  macro                            ;=======   Wait for a key pressed
  66.         xor     ah,ah                   ;  function 0 - wait for key pressed
  67.         int     16h                     ;  BIOS keyboard service
  68.         endm
  69.  
  70. SetCurs MACRO   Row,Column                        ;=======   Move the cursor
  71.         mov     ah,2                    ;  function 02h - set cursor position
  72.         xor     bh,bh                   ;  video page 0 is used
  73.         mov     dh,&Row                 ;  cursor row
  74.         mov     dl,&Column              ;  cursor column
  75.         int     10h                     ;  BIOS vide service call
  76.         ENDM
  77.  
  78. PutStr  MACRO   Row,Column,Text,Leng,Attrib
  79.         Local   M0
  80.         push    si
  81.         mov     cx,Leng                 ;  string length
  82.         lea     si,Text                 ;  DS:SI - address of text string
  83.         mov     dl,Column               ;  initial position (column)
  84.         cld                             ;  process strings from left to right
  85. ;  Outputting one character
  86. M0:     SetCurs Row,dl                  ;
  87.         lodsb                           ;  AL - character to be output
  88.         mov     bl,Attrib               ;  BL - attribute
  89.         mov     ah,9                    ;  function 09 - output char+attr
  90.         xor     bh,bh                   ;  video page 0 is used
  91.         push    cx                      ;  save cycle counter
  92.         mov     cx,1                    ;  number of characters output
  93.         int     10h                     ;  BIOS video service call
  94.         pop     cx                      ;  restore cycle counter
  95.         inc     dl                      ;  next position for output
  96.         loop    M0                      ;  next cycle step
  97.         pop     si                      ;
  98.         ENDM
  99.  
  100. ;-------------------------------------------------------------------
  101. .STARTUP
  102.         mov     ah,0Fh                  ;  function 0Fh - get video mode
  103.         int     10h                     ;  BIOS video service call
  104.         mov     VMODE,al                ;  save current video mode
  105.         mov     ah,0                                      ;  function 0 - set video mode
  106.         mov     al,3                    ;  80x25  Text
  107.         int     10h                     ;  BIOS video service call
  108. ;  Output initial message
  109.         OutMsg                   TEXT0                             ;  output initial message
  110.         WaitKey
  111. ;  check for mouse driver present
  112.         mov     ax, 03533h              ;  function 35h - get interrupt vector
  113.         int     21h                     ;  DOS service call
  114.         mov     ax,es                   ;  segment address of handler
  115.         or      ax,bx                   ;  AX - segment .OR. offset of int 33
  116.         jz      Nomouse                 ;  if full adders is 0 - no mouse
  117.         mov     bl,es:[bx]              ;  get first instruction of handler
  118.         cmp     bl,0CFh                 ;  is this IRET instruction?
  119.         jne     Begin                   ;  if not - driver installed
  120. Nomouse:
  121.         OutMsg  TEXT1                   ;  output message "driver not found"
  122.         WaitKey                                   ;  wait for key pressed
  123.         jmp     Exit                    ;  Exit program
  124. ;-------------------------------------------------------------------
  125. Begin:  OutMsg                   TEXT2                             ;  output message "driver installed"
  126.         WaitKey                                   ;  wait for key pressed
  127. ;-------------------------------------------------------------------
  128. ;  Initialize mouse and report status (function 0 of INT 33h)
  129. Func0:
  130.         xor     ax,ax                   ;  Initialize mouse
  131.         int     33h                     ;  mouse service call
  132.         cmp              ax,0                    ;  is mouse installed?
  133.         jnz     Clear25                 ;  if so, pass to function 10
  134.         jmp     Exit                    ;  if not, exit program
  135. ;  Fill the screen (yellow character on blue background)
  136. Clear25:SetCurs 0,0                     ;  cursor to left upper corner
  137.         mov     ah,9                    ;  function 09h - output char+attr
  138.         xor     bh,bh                   ;  video page  0 is used
  139.         mov     al,20h                  ;  character to be output
  140.         mov     bl,1Eh                  ;  attribute - yellow on blue
  141.         mov     cx,2000                 ;  number of characters to be output
  142.         int     10h                     ;  BIOS video service call
  143. ;-------------------------------------------------------------------
  144. ;  Output the header and the menu text onto the screen
  145.         PutStr  2,16,TEXT3,Ltxt3,1Eh
  146.         PutStr  8,20,TEXT8,Ltxt8,1Eh
  147.         PutStr  10,20,TEXT10,Ltxt10,1Fh
  148.         PutStr  11,20,TEXT11,Ltxt11,1Fh
  149.         PutStr  12,20,TEXT12,Ltxt12,1Fh
  150.         PutStr  13,20,TEXT13,Ltxt13,1Fh
  151.         PutStr  14,20,TEXT14,Ltxt14,1Fh
  152.         PutStr  15,20,TEXT15,Ltxt15,1Fh
  153.         SetCurs 25,80                   ;  move cursor out of screen
  154. ;-------------------------------------------------------------------
  155. ;  Function 10 - define text cursor
  156. Func10: mov     ax,10                   ;  define text cursor
  157.         xor     bx,bx                   ;  software cursor is used
  158.         mov     cx,0FFFFh               ;  screen Mask
  159.         mov     dx,4700h                ;  cursor Mask
  160.         int     33h                     ;  mouse service call
  161. ;-------------------------------------------------------------------
  162. ;  Function 1 - show the mouse cursor
  163. Func1:  mov     ax,1                    ;  function 01 - show mouse cursor
  164.         int     33h                     ;  mouse service call
  165. ;-------------------------------------------------------------------
  166. ;  Determining mouse keys pressed
  167. Func3:  mov     ah,1                    ;  function 01h - check keyboard buffer
  168.         int     16h                     ;  BIOS keyboard service
  169.         jz      ContF3                  ;  if no key pressed, continue
  170.         jmp     Exit                    ;  exit if key pressed
  171. ContF3: mov     ax,3                    ;  func. 03 - button status and location
  172.         int     33h                     ;  mouse service call
  173.         mov     CX0,cx                  ;  save  X coordinate (column)
  174.         mov     DX0,dx                  ;  save  Y coordinate (row)
  175.         test    bx,1                    ;  left button pressed?
  176.         jnz     X_Range                 ;  OK !
  177.         jmp     short Func3             ;  no button pressed - check again
  178. ;  Check horizontal cursor location
  179. X_Range:mov     ax,CX0                  ;  X coordinate (Column)
  180.         mov     cl,3                    ;  number bits to shift
  181.         shr     ax,cl                   ;  shift by 3 - divide by 8
  182.         cmp     ax,20                   ;  cursor on the left ?
  183.         jb      Func3                   ;  not - continue check
  184.         cmp     ax,36                   ;  cursor on the right?
  185.         ja      Func3                   ;  not - continue check
  186. ;  Check vertical cursor location
  187. Y_Range:mov     ax,DX0                  ;  X coordinate (Column)
  188.         mov     cl,3                    ;  number bits to shift
  189.         shr     ax,cl                   ;  shift by 3 - divide by 8
  190.         cmp     ax,10                   ;  cursor on the top ?
  191.         jb      Func3                   ;  not - continue check
  192.         cmp     ax,15                   ;  cursor on the bottom?
  193.         ja      Func3                   ;  not - continue check
  194. ;  report the number of the command selected
  195.         mov     ax,DX0                  ;  Y coordinate (Row)
  196.         mov     cl,3                    ;  number bits to shift
  197.         shr     ax,cl                   ;  shift by 3 - divide by 8
  198.         cmp     ax,15                   ;  line 15 (Exit) ?
  199.         je      Exit                    ;  if so - finish
  200.         sub     ax,9                    ;  number of command selected
  201.         or      al,30h                  ;  convert to ASCII character
  202.         mov     NumSel,al               ;  put number to output message
  203.         SetCurs 17,20                   ;  move cursor
  204.         OutMsg  TXT3L                   ;  output message "command selected"
  205.         jmp     short Func3             ;  check again
  206. ;-------------------------------------------------------------------
  207. ;  Terminate program and exit to DOS
  208. Exit:   mov     al,VMODE                ;  remember video mode on entry
  209.         mov              ah,0                     ;  function 0 - set video mode
  210.         int     10h                     ;  BIOS video service
  211.         Call    CLRKEY                  ;  clear keyboard buffer
  212.         mov     ax,4C00h                ;  function 4Ch - terminate process
  213.         int     21h                     ;  DOS service call
  214. ;-------------------------------------------------------------------
  215. ;
  216. ;   This procedure clears the keyboard buffer
  217. ;
  218. ;-------------------------------------------------------------------
  219. CLRKEY  PROC    NEAR uses ax es
  220.         mov              ax,40h                           ;  address of BIOS data segment
  221.         mov     ES,ax                   ;  ES points to BIOS data
  222.         cli                                       ;  no interrupts - system data modified
  223.         mov     ax,ES:[1Ah]             ;  buffer head printer
  224.         mov     ES:[1Ch],ax             ;  clear buffer (head ptr = tail ptr)
  225.         sti                                       ;  buffer cleared - allow interrupts
  226.         ret
  227. CLRKEY  ENDP
  228.         END
  229.